package servlet;

import dao.UserDaoImplement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String password = req.getParameter("password");
        UserDaoImplement ud = new UserDaoImplement();

        if (ud.login(name, password)) {
            // 登录成功
//            req.getRequestDispatcher("/home.jsp").forward(req, resp);

            resp.sendRedirect("/home.jsp");
        } else {
            resp.sendRedirect("/login.jsp");
        }
    }
}
